<?php
/**
 * CreateUser: zlh
 * CreateTime: 2022/2/2 15:12
 * Remark:
 */

namespace App\Service\Auth;

use App\Consts\AuthConsts\AuthConsts;
use App\Models\Auth\AuthBasicModel;
use App\Models\Auth\AuthMenuModel;

class AuthMenuService
{
    private AuthMenuModel $_authMenuModel;
    private AuthBasicModel $_authBasicModel;

    public function __construct()
    {
        $this->_authMenuModel = new AuthMenuModel();
        $this->_authBasicModel = new AuthBasicModel();
    }

    /**
     * 获取菜单
     * @return mixed
     */
    public function getAuthMenuMenu(){
        $menus =  $this->_authMenuModel->getAuthMenuMenu([
            'menu_id',
            'menu_name',
            'menu_url',
            'menu_parent_id',
        ]);
        foreach($menus as $key => $menu){
            $menus[$key]['auth_list'] =
                [
                    'operation' => $this->_authBasicModel->getAuthSelectByMenuId($menu['menu_id'],
                        AuthConsts::OPERATION_AUTH_TYPE,
                        [
                            'auth_id',
                            'auth_name',
                            'auth_code',
                        ]),
                    'manage' =>  $this->_authBasicModel->getAuthSelectByMenuId($menu['menu_id'],
                        AuthConsts::MANAGE_AUTH_TYPE
                        ,
                        [
                            'auth_id',
                            'auth_name',
                            'auth_code',
                        ])
                ];
        }
        return $menus;
    }
}